﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Media;
using System.Drawing;

namespace TankWin.Classes
{
    class GUIExit:GUI
    {
        public static SoundPlayer _exit_player;

        const int _Number = 2;
        protected int _curItem = 0;
        static string[] _menuItem = new string[_Number]
        {
            "YES",
            "NO"
        };
        public GUIExit()
        {
            try
            {
                _exit_player = new SoundPlayer();
                _exit_player.SoundLocation = @"C:\Windows\Media\Windows Shutdown.wav";
                try
                {
                    _exit_player.Load();
                }
                catch (System.Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.Message);
            	
            }
        }
        public override void Draw(System.Drawing.Graphics _G)
        {
            Bitmap _buffer = new Bitmap(300, 200);
            Graphics _gbuffer = Graphics.FromImage(_buffer);
            _gbuffer.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
            _gbuffer.Clear(Color.Black);

            Pen _pen = new Pen(Color.Silver, 10);
            _gbuffer.DrawRectangle(_pen, new Rectangle(0, 0, 300, 200));
            Font _font = new Font("Times New Roman", 20, FontStyle.Bold);
            Font _font1 = new Font(FontFamily.GenericSansSerif, 16, FontStyle.Bold);
            for (int i = 0; i < _Number; i++)
            {
                string _item = _menuItem[i];
                _gbuffer.DrawString(_item, _font, Brushes.White, new PointF(150 - 14 * _item.Length / 2, 70 + 35 * i));
                if (i== _curItem)
                {
                    _gbuffer.DrawString(_item, _font, Brushes.Red, new PointF(150 - 14 * _item.Length / 2, 70 + 35 * i));
                    _gbuffer.DrawString("O     ", _font, Brushes.Red, new PointF(150 - 14 * "O    ".Length, 70 + 35 * i));
                }


            }
            _G.DrawImageUnscaled(_buffer, 170, 220);

        }
        public override void InputKey(Keys _key)
        {
            if (GUIMainMenu._move_player.IsLoadCompleted && GUIPlay._hasSound)
                GUIMainMenu._move_player.Play();
            switch (_key)
            {
                case Keys.Up:
                    _curItem += _Number - 1;
                    _curItem %= _Number;
                    break;
                case Keys.Down:
                    _curItem++;
                    _curItem %= _Number;
                    break;
                case Keys.Left:
                    _curItem++;
                    _curItem %= _Number;
                    break;
                case Keys.Right:
                    _curItem += _Number - 1;
                    _curItem %= _Number;
                    break;
                case Keys.Enter:
                    if (GUIMainMenu._enter_player.IsLoadCompleted && GUIPlay._hasSound)
                        GUIMainMenu._enter_player.Play();
                    if (_curItem == 0)//yes
                    {
                        //frMain.SaveToFile();
                        if (_exit_player.IsLoadCompleted && GUIPlay._hasSound)
                        {
                            _exit_player.Play();
                            System.Threading.Thread.Sleep(1000);
                        }
                        Application.Exit();

                    }
                    if (_curItem == 1)//no
                    {
                        frMain._statusGUI = EStatusGUI.MainMenuGUI;
                    }
                    break;
            }
        }
    }
}
